package com.itxx.keyCase;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Scanner;

//新版本日期的转换[3]
public class NewDateDemo4 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //将LocalDateTime转换为String
        LocalDateTime localDateTime = LocalDateTime.now();
        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String format = localDateTime.format(pattern);
        System.out.println(format);
        //将String转换为LocalDateTime
        System.out.println("请输入格式为 yyyy-MM-dd HH:mm:ss 的时间:");
        String s = sc.next();
        LocalDateTime parse = LocalDateTime.parse(s, pattern);
        System.out.println(parse);
    }
}
